﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/shared/_LayoutFront.cshtml";
}
<style>
    .header-nav {
        background-color: #b9abce;
    }

    body {
        color: black;
    }
</style>

<div>
    <header class="header-article-list">
        <h1>在线留言</h1>

    </header>
    <div>
        <form class="message-form" method="post" onsubmit="return false">

            <label>
                姓名
                <input type="text" name="username" id="username">
                <span>*</span>
            </label>


            <label>
                电话
                <input type="text" name="tel" id="tel">
                <span>*</span>
            </label>


            <label>
                邮箱
                <input type="email" name="email" id="email">
                <span>*</span>
            </label>


            <label>
                内容
                <textarea name="content" id="content"></textarea>               
                <span>*</span>
            </label>


            <button type="button" class="am-btn am-btn-danger" id="sub">提交</button>
        </form>
    </div>
</div>
<script>
    $(function () {
        //当点击提交按钮的时候
        $("#sub").click(function () {
            //提交数据
            $.ajax({
                type: "post",
                url: "Messagesub",
                dataType: "json",
                data: {
                    Name: $("#username").val(),
                    Tel: $("#tel").val(),
                    Email: $("#email").val(),
                    Cont: $("#content").val(),
                },
                success: function (res) {
                    if (res.success == true) {
                        alert(res.msg);
                        $("#username").val(null);//清空页面上的数据
                        $("#tel").val(null);
                        $("#email").val(null);
                        $("#content").val(null);
                    } else {
                        alert(res.msg);
                    }
                }
            });
        });
    })
</script>

